from django.db import models


# Create your models here.

# 测试任务
class TestTask(models.Model):
    project = models.ForeignKey('project.Project', on_delete=models.CASCADE, verbose_name='所属项目')
    project_version = models.CharField(max_length=64, verbose_name='项目版本')
    name = models.CharField(max_length=64, verbose_name='任务名称')
    desc = models.CharField(max_length=256, verbose_name='任务描述')
    status_choices = (
        (0, '未执行'),
        (1, '执行中'),
        (2, '已完成'),
    )
    status = models.IntegerField(verbose_name='任务状态', default=0, choices=status_choices)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    def __str__(self):
        return f'{self.project.name} - {self.name}'

    class Meta:
        verbose_name = '测试任务'
        verbose_name_plural = verbose_name
        unique_together = ['project', 'name']


# 测试结果
class TestResult(models.Model):
    task = models.ForeignKey(TestTask, on_delete=models.CASCADE, verbose_name='所属任务')
    name = models.CharField(max_length=64, verbose_name='结果')
    desc = models.CharField(max_length=256, verbose_name='描述')
    status_choices = (
        (0, '未执行'),
        (1, '执行中'),
        (2, '已完成'),
    )
    status = models.IntegerField(verbose_name='结果状态', default=0, choices=status_choices)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    def __str__(self):
        return f'{self.task.name} - {self.name}'

    class Meta:
        verbose_name = '测试结果'
        verbose_name_plural = verbose_name
        unique_together = ['task', 'name']
